﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Framework.Project.Adapter.Native;
using AdvTicket.Common.Library;
using Framework.Project.Web.Mvc;
using AdvTicket.Admin.Web.Library;
using System.Reflection;
using Framework.Project.Web;

namespace AdvTicket.Admin.Web.Server
{
  public class MvcApplication : CHttpApplication
  {
    public override void Initialize()
    {
      // Eğer PartRecordListPage ile aynı url'yi yakalamk istiyor isek, Initialize 'dan önce 
      // Handlers içerisine register yapılmalı...
      // Gerek Kalmadı => 13.02.2013 tarihli geliştirme...
      //Handlers[CStaffListPage.Url] = new CHttpHandlerRouteProp() { urlConstantSegment = CStaffListPage.Url, urlConstantSegmentCount = 5, urlParameterSegmentCount = 0, handlerType = CHttpHandlerType.FrameworkHandler, httpHandler = typeof(CStaffListPage), IsUseMasterPage = true };

      base.Initialize();

      // Theme For DevExpres...
      ThemeName_DevEx = "Office2010Silver";
      ThemeName_Telerik = "Office2010Blue";

      // Version Info...
      ProgramVersion = CAdvTicketCommon.VersionInfo;

      MasterPageName = "MasterPage.cshtml";
      HtmlVersion = CAdvTicketCommon.HtmlVersion;
      HtmlIsMinify = CAdvTicketCommon.HtmlIsMinify;
      JsIsMinify = CAdvTicketCommon.JsIsMinify;
      CssIsMinify = CAdvTicketCommon.CssIsMinify;
      IsRequiredAuthentication = CAdvTicketCommon.IsRequiredAuthentication;
      VirtualPath = CAdvTicketAdmin.VirtualPath;
      // Admin Page
      ProjectWebPageTitleName = CAdvTicketAdmin.ProjectWebPageTitleName;
      MultiLanguageEnabled = true;
      IsDeleteResourceFilesWhenAppStart = CAdvTicketCommon.IsDeleteResourceFileWhenStart;

      // Eğer ID bilgisini verirse, Analytics üzerinden web sayfasına giriş bilgilerini takip edebilir.
      GoogleAnalyticsID = "";

      // Yüzde Modda daha güzel ekran yerleştirme yapılıyor...
		  PartPagePixelSizeMode = false;
      PartPageExtraHeight = 10;

      MultiLanguageKeyword = CAdvTicketCommon.MultiLanguageKeyword;


      // Login Page özelleştirilmeli...
      Handlers[LoginPageUrlName] = new CHttpHandlerRouteProp() { urlConstantSegment = LoginPageUrlName, urlConstantSegmentCount = 1, urlParameterSegmentCount = 0, handlerType = CHttpHandlerType.FrameworkHandler, httpHandler = typeof(CAdminLoginPage), IsUseMasterPage = false };


      // Örn'ler:
      // IController interface'inden türemiş, (projeye özel) HttpHandler'lar ekleyebilir.
      //base.Handlers["/test/"] = new CHttpHandlerRouteProp() { urlConstantSegment = "/test/", urlConstantSegmentCount = 1, urlParameterSegmentCount = 0, urlParameterSegment = "", handlerType = CHttpHandlerType.MvcHandler, controller = typeof(HomeController), action = "index" };
      //base.Handlers[this.MainPageUrlName] = new CHttpHandlerRouteProp() { urlConstantSegment = "/", urlConstantSegmentCount = 1, urlParameterSegmentCount = 0, IsUseMasterPage = true, IsUseTemplatePage = true, TemplatePageName = "Template.cshtml", httpHandler = typeof(TestMainPage) };

      Configuration = new CWebProjectApplicationConfiguration(
        CNativeProjectAdapterConfiguration.Create(CAdvTicketCommon.ProjectNo,
        CAdvTicketCommon.ServerConnectionInfo, CAdvTicketCommon.ConnectionInfo,
        CAdvTicketCommon.DatabaseType, CAdvTicketCommon.DatabaseName, null, null,
        CAdvTicketCommon.CachingEnabled, CAdvTicketCommon.NotLoadAllProjects),
        CAdvTicketCommon.ProjectNo, CAdvTicketCommon.CompanyUsageEnabled,
        CAdvTicketCommon.PeriodUsageEnabled, CAdvTicketAdmin.ProjectWebPageTitleName, "AdvTicket.png");
    }

    // CHttpApplication oluşturulmadan önceki Initialize...
    protected override void Application_Start(object sender, EventArgs e)
    {
      // Mvc Alanı
      //RegisterRoutes(RouteTable.Routes);

      // Base Initialize...
      base.Application_Start(sender, e);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
      /*
      routes.MapRoute(
          "test", // Route name
          "{controller}/{action}", // URL with parameters
          new { controller = "test", action = "Index"}
      );
       */

      /*
      RouteValueDictionary rv = new RouteValueDictionary();
      rv.Add("controller", "Home");
      rv.Add("action", "Index");
      rv.Add("id", "");
      Route customRoute = new Route("{controllerId}/{action}/{id}", rv, new CMvcRouteHandler());
      routes.Add(customRoute); 
      */
    }

  }
}